import { ref } from 'vue';
import { defineStore } from 'pinia';

export const useUserStore = defineStore('user', () => {
	const token = ref(uni.getStorageSync('token'));

	function setToken(value) {
		uni.setStorageSync('token', value);
		token.value = value;
	}

	const userinfo = ref(uni.getStorageSync('userinfo'));

	function setUserinfo(state) {
		uni.setStorageSync('userinfo', state);
		userinfo.value = { ...state };
	}

	return { token, setToken, userinfo, setUserinfo };
});